<?php
//进一法取整
//echo ceil(10.2);//输出11

//向下取整
//echo floor(10.2);

//找出最大值
//echo max(1,3);

//找出最小值
//echo min(1,3);


//echo min(max(1,$_GET['page']??1),100);

//对浮点数进行四舍五入处理
//echo round(12.567,2);

//mt_rand  生成随机码
//生成更好的随机数  下面数生成随机数的事例
function code(int $len = 4) : string
{
    $resource = '1234567890qwertyuiopasdfghjklzxcvbnm';
    $code = '';
    for($i = 0 ; $i < $len ; $i++){
        $code .= strtoupper($resource[mt_rand(0,strlen($resource)-1)]);
    }
    return $code;
}
//echo code();

//生成随机码
function getCode(int $len = 4):string
{
    $resource = '1234567890qwertyuiopasdfghjklzxcvbnm';
    $code = '';
    $start = 0;
    while($start < $len){
        $index = mt_rand(0,strlen($resource));
        $str = strtoupper($resource[$index]);
        $code .= $str;
        $start++;
    }
    return $code;
}

echo getCode(5);